package com.atguigu.srb.core.controller.admin;


import com.atguigu.common.results.R;
import com.atguigu.common.results.ResultCodeEnum;
import com.atguigu.srb.core.pojo.entity.UserInfo;
import com.atguigu.srb.core.pojo.query.UserQuery;
import com.atguigu.srb.core.service.UserInfoService;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户基本信息 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2022-10-24
 */
@RestController

@RequestMapping("/admin/core/userInfo")
public class AdminUserInfoController {
    @Autowired
    UserInfoService userInfoService;
    //管理员访问
    @ApiOperation("锁定/解锁会员")
    @PutMapping("lockOrUnlock/{userId}/{status}") //0 锁定  1解锁
    public R lockOrUnlock(@PathVariable("userId")String userId ,
                          @PathVariable("status") Integer status){
        boolean update = userInfoService.update(new LambdaUpdateWrapper<UserInfo>().eq(UserInfo::getId, userId)
                .set(UserInfo::getStatus, status));
        if(update){
            return R.success().message(status==0?"锁定成功":"解锁成功");

        }else {
            return R.error().message(status==0?"锁定失败":"解锁失败");
        }
    }
    @ApiOperation("查询会员分页列表")
    @GetMapping("list/{pageNum}/{pageSize}")
    public R listpage(@PathVariable("pageNum")Integer pageNum ,
                      @PathVariable("pageSize")Integer pageSize,
                      UserQuery userQuery){
        Page<UserInfo> page = new Page<>(pageNum, pageSize);
        userInfoService.getUserPage(page , userQuery);
        return R.success().data("page",page);
    }
}

